home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / falcon / nt_dsp1.lzh / NT_DSP1.MSA / LFLTS / LATIIR.HLP < prev    next >
Encoding:
Text File  |  1989-01-24  |  6.4 KB  |  152 lines

  1.          Name: LATIIR.ASM
  2.          Type: Assembler Macro
  3.       Version: 1.0
  4.   Last Change: 31-Jul-86
  5.  
  6.   Description: Lattice IIR Filter Assembler Macro
  7.  
  8.  BACKGROUND
  9.  
  10.  The filter described here is an all pole lattice filter.   The
  11.  basic section of a IIR lattice filter is show in Figure 4 .
  12.  
  13.  
  14.             >--------------(+)------------------------>
  15.         X(z)B[j](z)         ^        |            X(z)B[j-1](z)
  16.        -------------         \      /            ---------------
  17.          B[L](z)             -k    /                  B[L](z)
  18.                                \  /
  19.                                  /
  20.                                 / \
  21.          zX(z)C[j](z)          k   \            zX(z)C[j-1](z)
  22.         --------------        /     \          ----------------
  23.           B[L](z)            v       |              B[L](z)
  24.              <--------------(+)----------------1/z-----<
  25.  
  26.                             Figure 4
  27.  
  28.  
  29.  IMPLEMENTATION
  30.  
  31.  A third order all pole lattice IIR filter is shown in Figure 5.
  32.  
  33.                     
  34.   A  >---->(+)------------>(+)----------->(+)---------->----> A
  35.   (in)      ^      /        ^      /       ^      /       |  (out)
  36.              \    k3         \    k2        \    k1       |
  37.               \  /            \  /           \  /         |
  38.                 /               /              /          V
  39.                / \             / \            / \         |
  40.               /   \           /   \          /   \        |
  41.              /   -k3         /   -k2        /    -k1      |
  42.             v     |         v     |        v      |       |
  43.          --(+)<------1/z---(+)<-----1/z---(+)<-------1/z--|
  44.                   S3              S2             S1
  45.  
  46.                               Figure 5
  47.  
  48.  
  49.  
  50.  For the filter shown, the pointers R0 and R4  are  initialized
  51.  to point to the buffers as shown:
  52.  
  53.              R0                 R4
  54.               |                  |
  55.               v                  v
  56.    x:  k1 k2 k3        y: s1 s2 s3
  57.  
  58.        M0=2 (mod 3)       M4=2 (mod 3)
  59.  
  60.  The modulo registers are set to the number of coefficients  in
  61.  the  filter  minus  one  (in  this  example  there  are  three
  62.  coefficients).  The input sample is put in the A register  and
  63.  then  the filter macro is called.  The result of the filtering
  64.  operation is in A.  The output from the  bottom  left  is  not
  65.  saved or calculated.
  66.  
  67.  To use the filter, it is assumed the registers R0, R4, M0  and
  68.  M4  have  been  properly  initialized.  The input sample is in
  69.  register A and the filter is called as:
  70.  
  71.              latiir order              ;call fir lattice filter
  72.  
  73.  where 'latfir' is the macro name and 'order' is the number  of
  74.  reflection coefficients.
  75.  
  76.  FILTER OPERATION
  77.  
  78.  The operation of this filter can be described (refer to Figure
  79.  5 and the macro 'latiir'):
  80.  
  81.  1.  Assume the input sample is in register A and the  pointers
  82.      R0  and R4 are properly set.  The value at the bottom left
  83.      of Figure 5 is not needed so in this implementation of the
  84.      filter it is not calculated.
  85.  
  86.  2.  The first  MOVE  loads  the  first  k  (k3)  into  product
  87.      register  X0,  and  decrements  the pointer R0 to the next
  88.      coefficient.  Simultaneously, the filter state  is  loaded
  89.      and  the  pointer  R4  is incremented to point to the next
  90.      state.
  91.  
  92.  3.  The first section of the filter is  computed  by  the  MAC
  93.      instruction.   The coefficient k (X0) is multiplied by the
  94.      state (Y0) and the result is  subtracted  from  the  input
  95.      value  (A).   The  next  k coefficient (k2) is then loaded
  96.      into X0 and the pointer R0 is again decremented.  The next
  97.      state  is  the  loaded  into Y0 and the pointer R4 is then
  98.      decremented to point back to the previous state.  Now,  R4
  99.      points  back  to  the  state that was used in the previous
  100.      instruction.  Since that value is no  longer  needed,  the
  101.      new state computed will be stored in that location.
  102.  
  103.  4.  The DO loop now calculates the remaining filter  sections.
  104.      Since  the  first  section  was  calculated outside of the
  105.      loop, only ORDER-1 passes remain.
  106.  
  107.  5.  The  first  MAC  of  the  loop  updates  the  A  value  by
  108.      subtracting  the  product  of the coefficient (X0) and the
  109.      state (Y0).  The new state calculated (B) is saved in  the
  110.      previously  used  state  position  and  the  pointer R4 is
  111.      incremented to point to the current  state  position.   It
  112.      should  be noted that at this time, the previous state has
  113.      not been calculated so the first value that is written  is
  114.      unknown.
  115.  
  116.  6.  The top A value is moved into a product register  (X1)  so
  117.      it  can  be  multiplied  by  the  k coefficient (x0).  The
  118.      current state pointed to by  R4  is  reloaded  and  R4  is
  119.      incremented to point to the next state.
  120.  
  121.  7.  The new state is now calculated by adding the  product  of
  122.      the  top  value  (A)  and  the  k  coefficient (X0) to the
  123.      current state value (B).  A new k  coefficient  is  loaded
  124.      and  the  pointer R0 is decremented to point to the next k
  125.      coefficient.  The next state is loaded and the pointer  R4
  126.      is  decremented to point to the previously used state.  At
  127.      this point it should be observed that the next pass of the
  128.      loop will save the new state (B) that was just calculated.
  129.  
  130.  8.  Upon exiting from the loop, the output value  is  rounded,
  131.      the second last state is saved and the state pointer R4 is
  132.      incremented.
  133.  
  134.  9.  The pointer to the k coefficients is incremented by  using
  135.      a dummy load.  Since the pointer R0 is decremented 2 times
  136.      before entering  the  loop  and  the  loop  decrements  it
  137.      ORDER-1  times,  the  net number of decrements is ORDER+1.
  138.      Since there are  ORDER  number  of  coefficients  and  the
  139.      storage  is  modulo ORDER, the pointer must be incremented
  140.      to point to the k3 again.
  141.  
  142.      The output value in A is also saved as the last state  and
  143.      the pointer R4 is incremented to the next location.  It is
  144.      interesting to note that at this point, the value in A was
  145.      saved  over the unknown value in the state buffer that was
  146.      written in the first pass of the loop.  The state  pointer
  147.      R4  then points to the next state which is the first state
  148.      used on the next sample time.
  149.  
  150.  The benchmarks for this  filter  are:   9  instructions,  3N+4
  151.  instruction cycles, 2 stack locations.
  152.